#include "BeanieDebug.h"

void BeanieDebug::init(BeanieCore* a_core, int a_color)
{
	m_core = a_core;
	m_color = a_color;
}

void BeanieDebug::release()
{
	m_types.release();
	m_labels.release();
	m_ints.release();
	m_strings.release();
	m_floats.release();
}

void BeanieDebug::drawTLD()
{
	V2DF cursor;
	for(int i = 0; i < m_labels.size(); i++)
	{
		char string[128];
		switch(m_types[i])
		{ 
		case BD_INT:
			if(m_labels[i] != 0)
				sprintf_s(string,"%s%d\0",m_labels[i],*m_ints[i]);
			else
				sprintf_s(string,"%d\0",*m_ints[i]);
			break;
		case BD_STRING:
			if(m_labels[i] != 0)
				sprintf_s(string,"%s%s\0",m_labels[i],m_strings[i]);
			else
				sprintf_s(string,"%s\0",m_strings[i]);
			break;
		case BD_FLOAT:
			if(m_labels[i] != 0)
				sprintf_s(string,"%s%f\0",m_labels[i],*m_floats[i]);
			else
				sprintf_s(string,"%f\0",*m_floats[i]);
			break;
		}
		m_core->drawText(string,cursor,m_color);
		cursor.y += 16.0f;
	}
}

void BeanieDebug::drawBLD()
{
	V2DF cursor;
	cursor.y = m_core->getWindowHeight()-(m_labels.size()*16.0f);
	for(int i = 0; i < m_labels.size(); i++)
	{
		char string[128];
		switch(m_types[i])
		{ 
		case BD_INT:
			if(m_labels[i] != 0)
				sprintf_s(string,"%s%d\0",m_labels[i],*m_ints[i]);
			else
				sprintf_s(string,"%d\0",*m_ints[i]);
			break;
		case BD_STRING:
			if(m_labels[i] != 0)
				sprintf_s(string,"%s%s\0",m_labels[i],m_strings[i]);
			else
				sprintf_s(string,"%s\0",m_strings[i]);
			break;
		case BD_FLOAT:
			if(m_labels[i] != 0)
				sprintf_s(string,"%s%f\0",m_labels[i],*m_floats[i]);
			else
				sprintf_s(string,"%f\0",*m_floats[i]);
			break;
		}
		m_core->drawText(string,cursor,m_color);
		cursor.y += 16.0f;
	}
}

void BeanieDebug::watch(int* a_value)
{
	watch(0,a_value);
}

void BeanieDebug::watch(char* a_value)
{
	watch(0,a_value);
}

void BeanieDebug::watch(float* a_value)
{
	watch(0,a_value);
}

void BeanieDebug::watch(char* a_label, int* a_value)
{
	m_types.insertBack(BD_INT);
	m_labels.insertBack(a_label);

	m_ints.insertBack(a_value);
	m_strings.insertBack(0);
	m_floats.insertBack(0);
}

void BeanieDebug::watch(char* a_label, char* a_value)
{
	m_types.insertBack(BD_STRING);
	m_labels.insertBack(a_label);

	m_ints.insertBack(0);
	m_strings.insertBack(a_value);
	m_floats.insertBack(0);
}

void BeanieDebug::watch(char* a_label, float* a_value)
{
	m_types.insertBack(BD_FLOAT);
	m_labels.insertBack(a_label);

	m_ints.insertBack(0);
	m_strings.insertBack(0);
	m_floats.insertBack(a_value);
}

void BeanieDebug::clear()
{
	m_types.clear();
	m_labels.clear();
	m_ints.clear();
	m_strings.clear();
	m_floats.clear();
}